import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
	'user',
	() => {
		// 基本信息
		const setBasicInfo = ref({})

		// 返回地址
		const returnUrl = ref('/pages/index/index')
		const setReturnUrl = (url) => (returnUrl.value = url)
		// 返回类型
		const returnType = ref('switchTab')
		const setReturnType = (type) => (returnType.value = type)

		// 清除基本信息
		const removeBasicInfo = () => {
			setBasicInfo.value = {}
		}

		//重置返回url和类型
		const resetReturnUrlAndType = () => {
			//设置返回url为首页
			setReturnUrl('/pages/index/index')
			//设置返回类型为switchTab
			setReturnType('switchTab')
		}
		return {
			setBasicInfo,
			returnUrl,
			setReturnUrl,
			returnType,
			setReturnType,
			removeBasicInfo,
			resetReturnUrlAndType,
		}
	},
	{
		// 开启持久化
		persist: true,
	}
)
